#include "dft.h"

#include <math.h>

static const long double PI = 4.0L * atan(1.0L);

// calculeaza un termen al seriei Fourier 
// avand ca intrare conturul si ordinul termenului
FourierTerm dft(const Contour &contour, int u)
{
	unsigned int k, n;
	double p;
	FourierTerm result;
	Complex term;

	term.first  = 0.0;
	term.second = 0.0;

	n = contour.size();

	k = 0;
	for(Contour::const_iterator it_contour = contour.begin(); 
						it_contour != contour.end(); it_contour++)
	{
		const Point &current = *it_contour;
		p = 2.0L * PI * u * k / n;
		term.first  +=  current.first * cos(p) + current.second * sin(p);
		term.second += -current.first * sin(p) + current.second * cos(p);

		k++;
	}

	term.first  /= n;
	term.second /= n;

	result.first  = term;
	result.second = u;

	return result;
}